package com.wangyadong.hobby.concurrent;

import com.wangyadong.hobby.test.People;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

public class AtomicIntegerFieldUpdaterTest {

    public static void main(String[] args) {
        AtomicIntegerFieldUpdater<People> newUpdater = AtomicIntegerFieldUpdater.newUpdater(People.class, "age");
        People people = new People(10, "w");
        int andIncrement = newUpdater.incrementAndGet(people);
        assert andIncrement == 11;
        int w = newUpdater.addAndGet(people, 20);
        assert w == 31;
        int ijndex = newUpdater.get(people);
        assert ijndex == 31;
    }
}
